<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org/">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Spring Security SSO</title>
    <link rel="stylesheet"
          href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" />
</head>
<body>
<div class="container">
    <div class="col-sm-12">
        <h1>Spring Security SSO client-a</h1>
        Welcome, <span th:text="${#authentication.name}+'/'+${#authentication.userAuthentication.details.principal.nickname}"></span>
    </div>
    <div class="col-sm-12">
        <button class="btn btn-primary" id="test1">异步获取8881端口test接口数据</button>
        <button class="btn btn-primary" id="test2">异步获取8882端口test接口数据</button>
        <button class="btn btn-primary" id="logout">退出</button>
        <input id="access_token" type="hidden" th:value="${#authentication.details.tokenValue}">
    </div>
</div>

<script src="js/jquery-3.4.1.min.js"></script>
<script>
    $(function(){
        var access_token=$('#access_token').val();

        $('#test1').click(function(){
            $.ajax({
                url:'http://localhost:8881/test',
                headers:{
                    'Authorization': 'bearer '+access_token
                },
                success:function(data){
                    alert(data);
                }
            })
        });

        $('#test2').click(function(){
            $.ajax({
                url:'http://localhost:8882/test',
                headers:{
                    'Authorization': 'bearer '+access_token
                },
                success:function(data){
                    alert(data);
                }
            })
        });

        $('#logout').click(function() {
            $.ajax({
                url:'http://localhost:8881/logout',
                crossDomain:true,
                xhrFields:{
                    withCredentials: true
                }
            });
            $.ajax({
                url:'http://localhost:8882/logout',
                crossDomain:true,
                xhrFields:{
                    withCredentials: true
                }
            });
            var referer=location.href;
            location.href = "http://www.gdsspt.net:8080/logout?referer=" + referer+"&access_token="+access_token;
        })
    })

</script>
</body>
</html>